
//
//  GetDateManager.m
//  EnjoyLife
//
//  Created by ihope99 on 16/1/14.
//  Copyright © 2016年 Hepburn. All rights reserved.
//

#import "GetDateManager.h"


static GetDateManager *getDateManager = nil;

@implementation GetDateManager

+ (GetDateManager *)Share {
    if (!getDateManager) {
        getDateManager = [[GetDateManager alloc] init];
    }
    return getDateManager;
}


+(NSString *)getDateToStrWithinterval:(NSTimeInterval)interval WithStr:(NSString *)str
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateFormat = str;
    return [df stringFromDate:date];
}

+(NSString *)getDateToStrYYMM:(NSTimeInterval)interval;
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy年MM月";
    return [df stringFromDate:date];
}
+(NSString *)getDateToStrHHMMSS:(NSTimeInterval)interval;
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"HH:MM:SS";
    return [df stringFromDate:date];
}


+ (NSDate *)GetStartDate:(NSDate *)date {
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy-MM-dd";
    
    NSString *dateString = [df stringFromDate:date];
    return [df dateFromString:dateString];
}

+(NSString *)getDateToStrYYMMDD:(NSTimeInterval)interval
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy.MM.dd";
    return [df stringFromDate:date];
}

+(NSString *)getDateToStrType2:(NSTimeInterval)interval
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy-MM-dd";
    return [df stringFromDate:date];
}
+(NSString *)getDateToStrType3:(NSTimeInterval)interval
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    df.dateFormat = @"yyyy年MM月dd日";
    return [df stringFromDate:date];
}

+(NSString *)getDateToStrType4:(NSTimeInterval)startinterval :(NSTimeInterval)endinterval
{
    if (endinterval < startinterval)
    {
//        [AutoAlertView ShowAlert:@"提示" message:@"截止日期不能小于开始日期,请重新选择"];
        return @"错误";
    }
    NSTimeInterval interval = endinterval - startinterval;
    
    
    NSInteger oneDaySecs = 24*3600;
    return [NSString stringWithFormat:@"%lu天",(NSInteger)interval / oneDaySecs];
}

+(NSTimeInterval)getNewDate
{
    NSDate *currentDate = [NSDate date];
    NSTimeInterval a=[currentDate timeIntervalSince1970];
    return a;
}
+(NSTimeInterval)showDataWith:(NSString *)str{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
     [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    
    NSDate *date = [formatter dateFromString:str];

    NSTimeInterval mTimeInterVal = (long)[date timeIntervalSince1970];
    return mTimeInterVal;
}
+(NSString *)getAgeWithStr:(NSString *)str{
    //获取当前年月日
    NSString *myStr = [self getDateToStrType3:[self getNewDate]];
    
    NSArray *myArray = [myStr componentsSeparatedByString:@"日"];
    
    NSArray *OtherArr = [str componentsSeparatedByString:@"-"];
    
    int year = [myArray[0] intValue] - [OtherArr[0] intValue];
    
    return [NSString stringWithFormat:@"%d岁",year];
}
+(NSInteger)GetAfterMoom:(NSInteger)moom{
    NSDate * mydate = [NSDate date];
    
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    NSDateComponents *comps = nil;
    
    comps = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitMonth fromDate:mydate];
    
    NSDateComponents *adcomps = [[NSDateComponents alloc] init];
    
    [adcomps setYear:0];
    
    [adcomps setMonth:moom];
    
    [adcomps setDay:3];
    NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:mydate options:0];
    NSTimeInterval a=[newdate timeIntervalSince1970];
    return a;
}
+(NSInteger)GetAfterDay:(NSInteger)day{
    NSDate * mydate = [NSDate date];
    
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    
    NSDateComponents *comps = nil;
    
    comps = [calendar components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitMonth fromDate:mydate];
    
    NSDateComponents *adcomps = [[NSDateComponents alloc] init];
    
    [adcomps setYear:0];
    
    [adcomps setMonth:0];
    
    [adcomps setDay:day];
    NSDate *newdate = [calendar dateByAddingComponents:adcomps toDate:mydate options:0];
    NSTimeInterval a=[newdate timeIntervalSince1970];
    return a;
}

@end
